
//
//  FunctionHeadView.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/28.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "FunctionHeadView.h"
@interface FunctionHeadView()

@property(nonatomic,strong) MCButton *preMCBtn;
@end
@implementation FunctionHeadView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
//        self.backgroundColor = [UIColor blueColor];

        [self setUpUI];
    }
    return self;
}
-(void)setUpUI
{
    CGFloat w = kWidth/3;
    NSArray *titles = @[@"全部",@"需求",@"服务"];
    for (int i = 0; i < 3; i++) {
        self.mcBtn = [[MCButton alloc]initWithFrame:CGRectMake(i*w, 0, w, 40)];
        [self addSubview:self.mcBtn];
        [self.mcBtn setTitle:titles[i] forState:UIControlStateNormal];
        self.mcBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        self.mcBtn.buttonStyle = imageBottom;
        self.mcBtn.tag = i+1;
        [self.mcBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        if (i== 0) {
            [self.mcBtn setImage:[ImageColorHelper createImageWithColor:kOrangeBg] forState:UIControlStateNormal];
            [self.mcBtn setTitleColor:kLabel16Color forState:UIControlStateNormal];
            self.preMCBtn = self.mcBtn;
        }else{
            [self.mcBtn setImage:[UIImage new] forState:UIControlStateNormal];
            [self.mcBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
        }
        
    }
}
-(void)clickBtn:(MCButton *)clickBtn
{
    if (self.preMCBtn == clickBtn) {
        [clickBtn setImage:[ImageColorHelper createImageWithColor:kOrangeBg] forState:UIControlStateNormal];
        [clickBtn setTitleColor:kLabel16Color forState:UIControlStateNormal];
    }else {
        [clickBtn setImage:[ImageColorHelper createImageWithColor:kOrangeBg] forState:UIControlStateNormal];
        [clickBtn setTitleColor:kLabel16Color forState:UIControlStateNormal];
        [self.preMCBtn setImage:[UIImage new] forState:UIControlStateNormal];
        [self.preMCBtn setTitleColor:kLabel153Color forState:UIControlStateNormal];
    }
    
    self.preMCBtn = clickBtn;
    if ([self.delegate respondsToSelector:@selector(functionHeadView:withBtn:)]) {
        [self.delegate functionHeadView:self withBtn:clickBtn];
    }
}
@end
